import type { Router } from 'vue-router'
import { whitePathList } from '@/config'

export default (router: Router) => {
  router.beforeEach((to, from, next) => {
    if (localStorage.getItem('token')) {
      if (to.path === '/login') {
        next('/home')
      } else {
        next()
      }
    } else {
      if (whitePathList.includes(to.path)) {
        next()
      } else {
        next('/login')
      }
    }
  })
}
